
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _constant = require('../utils/constant');

// Utils
const _createNamespace = (0, _utils.createNamespace)('password-input');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

function PasswordInput(h, props, slots, ctx) {
  let _ref;

  const { mask } = props;
  const { value } = props;
  const { length } = props;
  const { gutter } = props;
  const { focused } = props;
  const { errorInfo } = props;
  const info = errorInfo || props.info;
  const Points = [];

  for (let i = 0; i < length; i++) {
    var _class;

    const _char = value[i];
    const showBorder = i !== 0 && !gutter;
    const showCursor = focused && i === value.length;
    let style = void 0;

    if (i !== 0 && gutter) {
      style = {
        marginLeft: (0, _utils.addUnit)(gutter),
      };
    }

    Points.push(h('li', {
      class: (_class = {}, _class[_constant.BORDER_LEFT] = showBorder, _class),
      style,
    }, [mask ? h('i', {
      style: {
        visibility: _char ? 'visible' : 'hidden',
      },
    }) : _char, showCursor && h('div', {
      class: bem('cursor'),
    })]));
  }

  return h('div', {
    class: bem(),
  }, [h('ul', (0, _babelHelperVueJsxMergeProps.default)([{
    class: [bem('security'), (_ref = {}, _ref[_constant.BORDER_SURROUND] = !gutter, _ref)],
    on: {
      touchstart: function touchstart(event) {
        event.stopPropagation();
        (0, _functional.emit)(ctx, 'focus', event);
      },
    },
  }, (0, _functional.inherit)(ctx, true)]), [Points]), info && h('div', {
    class: bem(errorInfo ? 'error-info' : 'info'),
  }, [info])]);
}

PasswordInput.props = {
  info: String,
  gutter: [Number, String],
  focused: Boolean,
  errorInfo: String,
  mask: {
    type: Boolean,
    default: true,
  },
  value: {
    type: String,
    default: '',
  },
  length: {
    type: [Number, String],
    default: 6,
  },
};

const _default = createComponent(PasswordInput);

exports.default = _default;
